<div class="form_content">
    <div class="job_tabs_section popup_form">
        <textarea id="<%= scope[:collection_name] -%>_template" class="template">
            <%= scope[:form].fields_for scope[:collection_name], :index => "" do |tab_form| %>
                <td class="name_value_cell name">
                    <%= tab_form.text_field :name, :class => "form_input environment_variable_name", :id => nil -%>
                </td>

                <td class="name_value_cell path">
                    <div>
                        <%= tab_form.text_field :path, :class => "form_input environment_variable_value", :id => nil -%>
                    </div>
                </td>
              <% unless scope[:read_only_page] %>
                <td class="name_value_cell">
                    <span class="icon_remove delete_parent"></span>
                </td>
              <% end %>
            <% end %>
        </textarea>
        <table class="<%= scope[:collection_name] -%>">
            <thead>
            <tr>
                <th><h4>Tab Name</h4>
                    <span class="contextual_help has_go_tip_right" title="Name of the tab which will appear in the Job Detail Page."></span>
                </th>
                <th class="path"><h4>Path</h4>
                    <span class="contextual_help has_go_tip_right" title="The artifact that will be rendered in the custom tab. This is typically a html or xml file."></span>
                </th>
                <th></th>
            </tr>
            </thead>
            <tbody class="<%= scope[:collection_name] -%>">
            <% scope[:collection].each do |tab| -%>
                <%= scope[:form].fields_for scope[:collection_name], tab, :index => "" do |tab_form| %>
                    <tr>
                        <td class="name_value_cell name">
                            <%= tab_form.text_field :name, :class => "form_input environment_variable_name", :id => nil -%>
                            <%= error_message_on(tab, com.thoughtworks.go.config.Tab::NAME, :css_class => "name_value_error") %>
                            <%= hidden_field_tag "#{scope[:form].object_name}[#{scope[:collection_name]}][][original_name]", tab.getName() %>
                        </td>
                        <td class="name_value_cell path">
                            <div>
                                <%= tab_form.text_field :path, :class => "form_input environment_variable_value", :id => nil -%>
                                <%= error_message_on(tab, com.thoughtworks.go.config.Tab::PATH, :css_class => "name_value_error") %>
                            </div>
                        </td>
                      <% unless scope[:read_only_page] %>
                        <td class="name_value_cell">
                            <span class="icon_remove delete_parent"></span>
                        </td>
                      <% end %>
                    </tr>
                <% end %>
            <%- end -%>
            </tbody>
        </table>
      <% unless scope[:read_only_page] %>
        <%= action_icon({:type => "add", :text => 'Add', :href => "#", :id => id="add_#{scope[:collection_name]}", :class => "skip_dirty_stop"}) %>
      <% end %>
        <div class="clear"></div>
    </div>
</div>
<script type="text/javascript">
    Util.on_load(function() {
        function setupVarForm(finish_button) {
            var rowCreator = new EnvironmentVariables.RowCreator(jQuery('#<%=scope[:collection_name]-%>_template'), 'tr', '.delete_parent');
            var variables = new EnvironmentVariables(
                    jQuery('tbody.<%=scope[:collection_name]-%>'),
                    rowCreator,
                    null,
                    function(inputs) {
                        inputs.dirty_form();
                    },
                    function(row) {
                        row.parents("form.dirtyform").data("dirty", true);
                    });

            variables.registerAddButton(jQuery("#add_<%=scope[:collection_name]-%>"))
            variables.addDefaultRow();
            variables.registerFinishButton(finish_button);
        }

        var finish_button = jQuery(".finish");
        setupVarForm(finish_button);
    });
</script>
